<?php

// src\Base\ForumBundle\Controller\TopicController.php
namespace Base\ForumBundle\Controller;

use Herzult\Bundle\ForumBundle\Controller\TopicController as HerzultTopicController;

class TopicController extends HerzultTopicController
{
    /*public function newAction(Category $category = null)
    {
        $response = parent::newAction($category);

        return $response;
    }

    public function createAction(Category $category = null)
    {
        $response = parent::createAction($category);

        return $response;
    }*/

    /*public function listAction($categorySlug, array $pagerOptions)
    {
        $response = parent::listAction($categorySlug, $pagerOptions);

        return $response;
    }*/

    public function showAction($categorySlug, $slug)
    {
        $topic = $this->findTopic($categorySlug, $slug);
        $this->get('herzult_forum.repository.topic')->incrementTopicNumViews($topic);

        if ('html' === $this->get('request')->getRequestFormat()) {
            $page = $this->get('request')->query->get('page', 1);
            $posts = $this->get('herzult_forum.repository.post')->findAllByTopic($topic, true);
            $posts->setCurrentPage($page);
            $posts->setMaxPerPage($this->container->getParameter('herzult_forum.paginator.posts_per_page'));
        } else {
            $posts = $this->get('herzult_forum.repository.post')->findRecentByTopic($topic, 30);
        }

        $template = sprintf('%s:show.%s.%s', $this->container->getParameter('herzult_forum.templating.location.topic'), $this->get('request')->getRequestFormat(), $this->getRenderer());

        /* Breadcrumbs */
        $breadcrumbs = $this->get( 'white_october_breadcrumbs' );
        $breadcrumbs->addItem( 'Accueil', $this->get('router')->generate( '_homepage' ));
        $breadcrumbs->addItem( 'Forum', $this->get('router')->generate( 'herzult_forum_index' ));
        $breadcrumbs->addItem( $topic->getSubject() );

        return $this->get('templating')->renderResponse($template, array(
            'topic' => $topic,
            'posts' => $posts
        ));
    }

    public function postNewAction($categorySlug, $slug)
    {
        $response = parent::postNewAction($categorySlug, $slug);

        return $response;
    }

    public function postCreateAction($categorySlug, $slug)
    {
        $response = parent::postCreateAction($categorySlug, $slug);

        return $response;
    }

    public function deleteAction($id)
    {
        $response = parent::deleteAction($id);

        return $response;
    }
}
